package com.citsin.atlas.adapter

import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.citsin.atlas.R
import com.citsin.atlas.bean.Media

/**
 * citsin
 * 2019-06-04
 */
class MediaPreviewAdapter : PagedListPagerAdapter<Media>() {

    override fun createItem(container: ViewGroup, position: Int): Any {
        val root = LayoutInflater.from(container.context).inflate(R.layout.item_media_preview, container, false)
        val itemValue = pagedList?.get(position)
        val imageView:ImageView = root.findViewById(R.id.imageView)
        Glide.with(container.context).load(Uri.parse(itemValue!!.uri)).into(imageView)
        container.addView(root)
        return root
    }

    override fun removeItem(container: ViewGroup, position: Int, obj: Any) {
        container.removeView(obj as View)
    }
}
